<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // let arr = [1, 2, 3];
        // let { 0: first, [arr.length - 1]: last } = arr;
        // first // 1
        // last // 3

        const [a, b, c, d, e] = 'hello';
        // 字符串类似数组的对象都有一个length属性，因此还可以对这个属性解构赋值。
        const { length: len } = 'haha';
        console.log(len);
        console.log(a);

        function move({ x = 0, y = 0 } = {}) {//解构，然后有默认值
            return [x, y];
        }

        console.log(move({ x: 3, y: 8 }));// [3, 8]);
        move({ x: 3 }); // [3, 0]
        move({}); // [0, 0]
        move(); // [0, 0]


        let { foo: baz } = { foo: 'aaa', bar: 'bbb' };
        console.log(baz);
    </script>
</body>

</html>